package com.zhy.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zhy.sunmi.bean.SoldGoodDetail;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SOLD_GOOD_DETAIL".
*/
public class SoldGoodDetailDao extends AbstractDao<SoldGoodDetail, Long> {

    public static final String TABLENAME = "SOLD_GOOD_DETAIL";

    /**
     * Properties of entity SoldGoodDetail.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property SellGoodHistoryId = new Property(1, Long.class, "sellGoodHistoryId", false, "SELL_GOOD_HISTORY_ID");
        public final static Property ProductId = new Property(2, Long.class, "productId", false, "PRODUCT_ID");
        public final static Property EnglishName = new Property(3, String.class, "englishName", false, "ENGLISH_NAME");
        public final static Property ChineseName = new Property(4, String.class, "chineseName", false, "CHINESE_NAME");
        public final static Property Number = new Property(5, Long.class, "number", false, "NUMBER");
        public final static Property Price = new Property(6, double.class, "price", false, "PRICE");
        public final static Property Discount = new Property(7, String.class, "discount", false, "DISCOUNT");
        public final static Property PriceAfterDis = new Property(8, double.class, "priceAfterDis", false, "PRICE_AFTER_DIS");
        public final static Property TotalPrice = new Property(9, double.class, "totalPrice", false, "TOTAL_PRICE");
        public final static Property TotalPriceAfterDis = new Property(10, double.class, "totalPriceAfterDis", false, "TOTAL_PRICE_AFTER_DIS");
        public final static Property Vat = new Property(11, double.class, "vat", false, "VAT");
        public final static Property VatMoney = new Property(12, double.class, "vatMoney", false, "VAT_MONEY");
        public final static Property No_discount = new Property(13, String.class, "no_discount", false, "NO_DISCOUNT");
        public final static Property Hot_goods = new Property(14, String.class, "hot_goods", false, "HOT_GOODS");
    }

    private Query<SoldGoodDetail> sellGoodHistory_SoldGoodDetailsQuery;

    public SoldGoodDetailDao(DaoConfig config) {
        super(config);
    }
    
    public SoldGoodDetailDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SOLD_GOOD_DETAIL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"SELL_GOOD_HISTORY_ID\" INTEGER," + // 1: sellGoodHistoryId
                "\"PRODUCT_ID\" INTEGER," + // 2: productId
                "\"ENGLISH_NAME\" TEXT," + // 3: englishName
                "\"CHINESE_NAME\" TEXT," + // 4: chineseName
                "\"NUMBER\" INTEGER," + // 5: number
                "\"PRICE\" REAL NOT NULL ," + // 6: price
                "\"DISCOUNT\" TEXT," + // 7: discount
                "\"PRICE_AFTER_DIS\" REAL NOT NULL ," + // 8: priceAfterDis
                "\"TOTAL_PRICE\" REAL NOT NULL ," + // 9: totalPrice
                "\"TOTAL_PRICE_AFTER_DIS\" REAL NOT NULL ," + // 10: totalPriceAfterDis
                "\"VAT\" REAL NOT NULL ," + // 11: vat
                "\"VAT_MONEY\" REAL NOT NULL ," + // 12: vatMoney
                "\"NO_DISCOUNT\" TEXT," + // 13: no_discount
                "\"HOT_GOODS\" TEXT);"); // 14: hot_goods
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SOLD_GOOD_DETAIL\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SoldGoodDetail entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long sellGoodHistoryId = entity.getSellGoodHistoryId();
        if (sellGoodHistoryId != null) {
            stmt.bindLong(2, sellGoodHistoryId);
        }
 
        Long productId = entity.getProductId();
        if (productId != null) {
            stmt.bindLong(3, productId);
        }
 
        String englishName = entity.getEnglishName();
        if (englishName != null) {
            stmt.bindString(4, englishName);
        }
 
        String chineseName = entity.getChineseName();
        if (chineseName != null) {
            stmt.bindString(5, chineseName);
        }
 
        Long number = entity.getNumber();
        if (number != null) {
            stmt.bindLong(6, number);
        }
        stmt.bindDouble(7, entity.getPrice());
 
        String discount = entity.getDiscount();
        if (discount != null) {
            stmt.bindString(8, discount);
        }
        stmt.bindDouble(9, entity.getPriceAfterDis());
        stmt.bindDouble(10, entity.getTotalPrice());
        stmt.bindDouble(11, entity.getTotalPriceAfterDis());
        stmt.bindDouble(12, entity.getVat());
        stmt.bindDouble(13, entity.getVatMoney());
 
        String no_discount = entity.getNo_discount();
        if (no_discount != null) {
            stmt.bindString(14, no_discount);
        }
 
        String hot_goods = entity.getHot_goods();
        if (hot_goods != null) {
            stmt.bindString(15, hot_goods);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SoldGoodDetail entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long sellGoodHistoryId = entity.getSellGoodHistoryId();
        if (sellGoodHistoryId != null) {
            stmt.bindLong(2, sellGoodHistoryId);
        }
 
        Long productId = entity.getProductId();
        if (productId != null) {
            stmt.bindLong(3, productId);
        }
 
        String englishName = entity.getEnglishName();
        if (englishName != null) {
            stmt.bindString(4, englishName);
        }
 
        String chineseName = entity.getChineseName();
        if (chineseName != null) {
            stmt.bindString(5, chineseName);
        }
 
        Long number = entity.getNumber();
        if (number != null) {
            stmt.bindLong(6, number);
        }
        stmt.bindDouble(7, entity.getPrice());
 
        String discount = entity.getDiscount();
        if (discount != null) {
            stmt.bindString(8, discount);
        }
        stmt.bindDouble(9, entity.getPriceAfterDis());
        stmt.bindDouble(10, entity.getTotalPrice());
        stmt.bindDouble(11, entity.getTotalPriceAfterDis());
        stmt.bindDouble(12, entity.getVat());
        stmt.bindDouble(13, entity.getVatMoney());
 
        String no_discount = entity.getNo_discount();
        if (no_discount != null) {
            stmt.bindString(14, no_discount);
        }
 
        String hot_goods = entity.getHot_goods();
        if (hot_goods != null) {
            stmt.bindString(15, hot_goods);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public SoldGoodDetail readEntity(Cursor cursor, int offset) {
        SoldGoodDetail entity = new SoldGoodDetail( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // sellGoodHistoryId
            cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // productId
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // englishName
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // chineseName
            cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5), // number
            cursor.getDouble(offset + 6), // price
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // discount
            cursor.getDouble(offset + 8), // priceAfterDis
            cursor.getDouble(offset + 9), // totalPrice
            cursor.getDouble(offset + 10), // totalPriceAfterDis
            cursor.getDouble(offset + 11), // vat
            cursor.getDouble(offset + 12), // vatMoney
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // no_discount
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14) // hot_goods
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SoldGoodDetail entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setSellGoodHistoryId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setProductId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2));
        entity.setEnglishName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setChineseName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setNumber(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5));
        entity.setPrice(cursor.getDouble(offset + 6));
        entity.setDiscount(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setPriceAfterDis(cursor.getDouble(offset + 8));
        entity.setTotalPrice(cursor.getDouble(offset + 9));
        entity.setTotalPriceAfterDis(cursor.getDouble(offset + 10));
        entity.setVat(cursor.getDouble(offset + 11));
        entity.setVatMoney(cursor.getDouble(offset + 12));
        entity.setNo_discount(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setHot_goods(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(SoldGoodDetail entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(SoldGoodDetail entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SoldGoodDetail entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "soldGoodDetails" to-many relationship of SellGoodHistory. */
    public List<SoldGoodDetail> _querySellGoodHistory_SoldGoodDetails(Long sellGoodHistoryId) {
        synchronized (this) {
            if (sellGoodHistory_SoldGoodDetailsQuery == null) {
                QueryBuilder<SoldGoodDetail> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.SellGoodHistoryId.eq(null));
                sellGoodHistory_SoldGoodDetailsQuery = queryBuilder.build();
            }
        }
        Query<SoldGoodDetail> query = sellGoodHistory_SoldGoodDetailsQuery.forCurrentThread();
        query.setParameter(0, sellGoodHistoryId);
        return query.list();
    }

}
